package http

import (
	"fmt"
	"log"
	"net/http"
)

func sayHelloName(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello world!") //这个写入到w的是输出到客户端的
}

func postForm(w http.ResponseWriter, req *http.Request) {
	name := req.PostFormValue("name")
	fmt.Fprintf(w, name)
}
func info(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()       //解析参数，默认是不会解析的
	fmt.Println(r.Form) //这些信息是输出到服务器端的打印信息
	fmt.Println("path", r.URL.Path)
	fmt.Println("scheme", r.URL.Scheme)
	fmt.Println(r.Form["url_long"])
}
func Httpserver() {
	http.HandleFunc("/", sayHelloName)     //设置访问的路由
	http.HandleFunc("/postForm", postForm) //设置访问的路由

	err := http.ListenAndServe(":9090", nil) //设置监听的端口
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
